class Solution {
    int Min(int n1, int n2, int n3){
        int res = (n1 < n2) ? n1 : n2;
        res = (res < n3) ? res : n3;
        return res;
    }
public:
    int GetUglyNumber_Solution(int index) {
        if(0 == index) return 0;
        int* uglynum = new int [index];
        uglynum[0] = 1;
        int k = 1 ;
        
        int* p2 = uglynum, *p3 = uglynum, *p5 = uglynum;
        while(k < index){
            int num = Min(*p2 * 2, *p3 * 3, *p5 * 5);
            uglynum[k] = num;
            
            while(*p2 * 2 <= num)
                ++p2;
            while(*p3 * 3 <= num)
                ++p3;
            while(*p5 * 5 <= num)
                ++p5;
            k += 1;
        }
        int res = uglynum[k-1];
        delete[] uglynum;
        return res;
    }
};